home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 1 of 3.iso / chapte21 / ex18.c < prev    next >
C/C++ Source or Header  |  1995-05-29  |  3KB  |  68 lines

  1. #include <genstub.c>
  2.  
  3. LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  4. {
  5.    switch (uMsg)
  6.    {
  7.          case WM_CREATE:  // Set current directory to value passed on command line.
  8.          {
  9.                char   szMessage[MAX_PATH + 31];
  10.                char   szCommandLine[MAX_PATH + 1];
  11.                LPTSTR lpToken = NULL;
  12.                LPTSTR lpszDirName = NULL;
  13.                DWORD  dwcCurDir = MAX_PATH;
  14.  
  15.                lstrcpy( szCommandLine, GetCommandLine() );
  16.                // Search for extra input after program name.
  17.                if ( ( lpToken = strstr( szCommandLine, " " ) ) )
  18.                {
  19.                   // Get first argument by itself, if there is one.
  20.                   lpszDirName = strtok( lpToken, " " );
  21.                   if ( lpszDirName )
  22.                   {
  23.                      // Use lpTemp pointer to isolate 1st arg.
  24.                      LPTSTR lpTemp = strstr(lpszDirName, " ");
  25.                      if (lpTemp)
  26.                         *lpTemp = 0;
  27.                      // Attempt to change the current directory.
  28.                      if ( !SetCurrentDirectory(lpszDirName) )
  29.                         wsprintf( szMessage,
  30.                                   "Cannot set current directory to [%s]",
  31.                                   lpszDirName );
  32.                      else
  33.                         wsprintf( szMessage, "Set current directory to [%s]",
  34.                                   lpszDirName );
  35.                      // Report result of operation.
  36.                      MessageBox( hWnd, szMessage,
  37.                                  "Result of SetCurrentDirectory()", MB_OK );
  38.                   }
  39.                }
  40.          }
  41.          return DefWindowProc( hWnd, uMsg, wParam, lParam );
  42.  
  43.          case WM_COMMAND:
  44.                switch ( LOWORD( wParam ) )
  45.                {
  46.                      case IDM_TEST:
  47.                      {
  48.                            char szBuffer[MAX_PATH + 1];
  49.                            DWORD dwcNameSize = MAX_PATH + 1;
  50.  
  51.                            // Now query the system for the paths.
  52.                            GetCurrentDirectory( dwcNameSize, &szBuffer );
  53.                            MessageBox( hWnd, szBuffer, "Current Directory", MB_OK );
  54.                      }
  55.                      break;
  56.                      case IDM_EXIT:
  57.                            DestroyWindow( hWnd );
  58.                            break;
  59.                }
  60.                break;
  61.          case WM_DESTROY:
  62.                PostQuitMessage( 0 );
  63.                break;
  64.          default:
  65.                return (DefWindowProc(hWnd, uMsg, wParam, lParam));
  66.    }
  67.    return (NULL);
  68. }